aboutsummaryrefslogtreecommitdiff
path: root/]
blob: f335939d74b06886cb778ea8ac3e9f1a860af415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "maxCommands.h"

#define cs 6
#define clk 5
#define dataIn 3


void setup() {
	Serial.begin(9600);

	Serial.println("Starting up \n\n\n");

	pinMode(cs, OUTPUT);
	pinMode(clk, OUTPUT);
	pinMode(dataIn, OUTPUT);


	digitalWrite(cs, HIGH);
	
	writeCommand(maxSHUTDOWN_INV, 1);

	writeCommand(maxINTENSITY, 0x00);


}

void loop() {

	for ( int i = 0; i < 255; i++) {
		writeCommand(maxDIGIT_1, i);

		delay(200);
	}

}


void writeCommand(uint8_t addr, uint8_t data) {
	uint16_t byteToWrite = addr << 8 | data;

	//Set Chip select low
	digitalWrite(cs, LOW);

	Serial.print("Writing: ");
	for (int i = 0; i < 16; i++) {
		bool bitToWrite = ( byteToWrite & 1 << 15 - i ) > 0;
		Serial.print( bitToWrite );
		
		//Write Data
		digitalWrite(dataIn, bitToWrite);
		delayMicroseconds(10);	

		//Write clock
		digitalWrite(clk, HIGH);

		//Wait and go low
		delayMicroseconds(100);
		digitalWrite(clk, LOW);
	}
	digitalWrite(cs, HIGH);
	Serial.println();
}